<template>
  <div class="hometop">
    <div class="hometopitem">
      <div style="font-size:14px;color:#070707">今日注册用户：</div>
      <div style="font-size:20px;margin-left:10px;color:#070707">{{  datalist.register }}</div>
    </div>
    <div class="hometopitem">
      <div style="font-size:14px;color:#070707">论坛今日访问人次：</div>
      <div style="font-size:20px;margin-left:10px;color:#070707">{{  datalist.pvshow }}</div>
    </div>
    <div class="hometopitem">
      <div style="font-size:14px;color:#070707">今日发帖数：</div>
      <div style="font-size:20px;margin-left:10px;color:#070707">{{  datalist.post }}</div>
    </div>
    <div class="hometopitem">
      <div style="font-size:14px;color:#070707">今日回复数：</div>
      <div style="font-size:20px;margin-left:10px;color:#070707">{{  datalist.reply }}</div>
    </div>
    <div id="myChart" style="padding-left: 20px;margin-top: 20px" :style="{width: '1200px', height: '600px'}"></div>
  </div>
</template>
<script>
import { getsati } from '../../api/classify'
let echarts = require('echarts/lib/echarts')
// 引入柱状图组件
require('echarts/lib/chart/line')
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
const Files = require.context('@/icons/icon', false, /\.png$/)
export default {
  name: 'Classify',
  data() {
    return {
      datalist: {},
      icons: Files.keys().map(key => Files(key)),
      week: {},
      legenddata: [],
      xAxisdata: [],
      seriesdata: {}
    }
  },
  created() {
    this._getTableData()
  },
  methods: {
    _getTableData() {
      getsati().then(res => {
        this.week = res.week
        this.legenddata = res.week.legend.data
        this.xAxisdata = res.week.xAxis.data
        this.seriesdata = res.week.series
        // const { data = [] } = res || {}
        this.datalist = res
        this.drawLine()
      })
    },
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = echarts.init(document.getElementById('myChart'))
      // 绘制图表
      myChart.setOption({
         title: {
          text: '回帖折线图'
        },
        tooltip: {
          trigger: 'axis'
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        legend: {
          data: this.legenddata
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: this.xAxisdata
        },
        yAxis: {
            type: 'value'
        },
        series: this.seriesdata
      })
    },
    btn({ url }) {
      this.$router.push({
        path: url
      })
    }
  }
}
</script>
<style>
.active{
  cursor: pointer;
}
.hometop{
  padding: 0 0 20px 0;
  width: 100%;
  border-radius: 4px;
   background: white;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
   /* background: rgb(242, 241, 246); */
   box-sizing: border-box;
}
.hometopitem{
  margin: 20px;
  padding-left: 15px;
  width: 20%;
  height: 100px;
  background: rgb(221, 220, 220);
  box-sizing: border-box;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.htir{
  margin-left: 15px;
}
.icos{
  margin-left: 10px;
  display: inline-block;
  width: 25px;
  height: 25px;
  text-align: center;
  line-height: 25px;
  font-size: 20px;
  border-radius: 50%;
  border: 1px solid #cccccc;
  box-sizing: border-box;
}
.el-input {
    margin-right: 10px;
    position: relative;
    font-size: 14px;
    display: inline-block;
    width: 100% !important;
}
</style>

